import React, { useEffect, useState } from 'react'
import server from '../../http/request'
import { Menu, Layout, Button } from 'antd';
import { AppstoreOutlined, MailOutlined, SettingOutlined } from '@ant-design/icons';
import router from 'umi/router';

const { Header, Footer, Sider, Content } = Layout;
function getItem(label, key, icon, children, type) {
    return {
      key,
      icon,
      children,
      label,
      type,
    };
  }
  
function Root(props) {
    const [menus, setMenus] = useState([])

    const items = [
        getItem('用户管理', '/users', <AppstoreOutlined />, [
            getItem('用户列表', '/users'),
        ]),
        getItem('权限管理', '/rights', <SettingOutlined />, [
            getItem('角色列表', '/roles'),
            getItem('权限列表', '/rights'),
        ]),
        getItem('商品管理', 'shop', <SettingOutlined />, [
            getItem('商品列表', '/goods'),
            getItem('分类参数', '/params'),
            getItem('商品分类', '/categories'),
        ]),
    ];
    const onClick = (e) => {
        console.log('click ', e);
        router.push(e.key)
    };
    const getMenu = async () => {
        const res = await server.get('/menus')
        setMenus(res.data)
    }
    const logout=()=>{
        router.push("/login")
        sessionStorage.removeItem("token")
        
    }
    useEffect(() => {
        getMenu()
    }, [])
    return (
        <Layout style={{ height: "100%" }}>
            <Header style={{ background: '#fff' }}>
                <Button onClick={logout}>退出</Button>
            </Header>
            <Layout>
                <Sider style={{ background: '#fff' }}>
                    <Menu
                        onClick={onClick}
                        // defaultSelectedKeys={['1']}
                        // defaultOpenKeys={['sub1']}
                        // mode="inline"
                        items={items}
                    />
                </Sider>
                <Content>{props.children}</Content>
            </Layout>
        </Layout>
    )
}

export default Root
